package chinaums

import (
    "errors"
	"github.com/astaxie/beego"
)

/*
type ChinaUmsNotifyMsg struct {
	PayTime        string  `form:"payTime,omitempty"`
	ConnectSys     string  `form:"connectSys,omitempty"`
	//随机key-value
	Sign           string  `form:"sign"`
	Mid            string  `form:"mid,omitempty"`
	InvoiceAmount  int     `form:"invoiceAmount,omitempty"`
	SettleDate     string  `form:"settleDate,omitempty"` 
	BillFunds      string  `form:"billFunds,omitempty"`
	BuyerId        string  `form:"buyerId,omitempty"`
	MchntUuid      string  `form:"mchntUuid,omitempty"`
	Tid            string  `form:"tid,omitempty"`
	CouponAmount   int     `form:"couponAmount,omitempty"`
	TargetOrderId  string  `form:"targetOrderId,omitempty"` 
	BillFundsDesc  string  `form:"billFundsDesc,omitempty"`
	SubBuyerId     string  `form:"subBuyerId,omitempty"` 
	OrderDesc      string  `form:"orderDesc,omitempty"`
	SeqId          string  `form:"seqId,omitempty"` 
	MerOrderId     string  `form:"merOrderId,omitempty"`
	TargetSys      string  `form:"targetSys,omitempty"`
	BankInfo       string  `form:"bankInfo,omitempty"`
	TotalAmount    int     `form:"totalAmount,omitempty"`
	BuyerPayAmount int     `form:"buyerPayAmount,omitempty"`
	NotifyId       string  `form:"notifyId,omitempty"`
	SubInst        int     `form:"subInst,omitempty"`
	AttachedData   string  `form:"attachedData,omitempty"`
	Status         string  `form:"status,omitempty"` 	
}
*/

func ChinaUmsNotify(message,secreCode string)(map[string]interface{}, error){
	decoder := NewForm(message)
    rspMap, err := decoder.Decode()       //map[string]interface{}
	if err != nil {
	    beego.Debug("err:", err.Error())
		return nil, err
	}
	
	sign := NotifyMakeSign(rspMap, secreCode)
	//beego.Debug("calc sign:", sign)
	//beego.Debug("origin sign:", rspMap["sign"])
	//
	if rspMap["sign"] != sign {
		beego.Debug("response sign err......")
		return nil, errors.New("response sign err")
	}
	return rspMap, nil
}
